package freespiritsocial.io.user.viewmodel

import com.sendbird.android.GroupChannel
import freespiritsocial.io.user.chat.ChannelManager
import freespiritsocial.io.user.data.model.bean.ApiRefreshResult
import freespiritsocial.io.user.viewmodel.delegates.UserInfoViewModel
import me.hgj.jetpackmvvm.callback.databind.StringObservableField
import me.hgj.jetpackmvvm.callback.livedata.UnPeekLiveData
import me.hgj.jetpackmvvm.ext.requestNoCheck

/**
 * @description
 * @author csw
 * @date 2021-10-17
 */
class MessageViewModel: UserInfoViewModel() {
    val searchText = StringObservableField()
    val channelResult = UnPeekLiveData<ApiRefreshResult<GroupChannel>>()

    fun getChatList(refresh: Boolean = false) {
        requestNoCheck({
            ChannelManager.getChannelList(refresh,searchText.get())
        },{
            channelResult.postValue(ApiRefreshResult(refresh,it,it.size >= 20))
        })
    }
}